package com.itheima.config;

import com.itheima.interceptors.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import java.util.List;

/**
 * @Date :2019-08-17 10:04
 * @Author : yuan_he_song
 */
@Configuration
public class SystemConfig extends WebMvcConfigurationSupport {

    @Autowired
    private JwtInterceptor jwtInterceptor;

    @Override /** 添加拦截器的配置 */
    protected void addInterceptors(InterceptorRegistry registry) {
        // 添加自定义拦截器
        registry.addInterceptor(jwtInterceptor)
                /** 拦截指定的url地址 */
                .addPathPatterns("/**")
                /** 指定不拦截的url地址 */
                .excludePathPatterns("/user/login","/user/logout","/user/register");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new CurrentUserArgumentResolver());
        super.addArgumentResolvers(argumentResolvers);
    }

}
